package stud.aistar.mybatis.utils;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

/**
 * @author wangyu
 * @version 1.0
 * @description
 * @createDate 2019/8/22 23:05
 */
public class    MybatisUtil {

    private static SqlSessionFactory sqlSessionFactory = null;

    static {
        try {
            InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("mybatis-config.xml");
            sqlSessionFactory = new SqlSessionFactoryBuilder().build(in);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static SqlSession sqlSession(){
        return sqlSessionFactory.openSession();
    }
}
